package com.yjc.drygoods.order.controller;

import com.alipay.api.AlipayApiException;
import com.yjc.drygoods.order.config.AlipayTemplate;
import com.yjc.drygoods.order.service.OrderService;
import com.yjc.drygoods.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author yjc
 * @create 2022-09-29 9:39
 */
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getPayVo(orderSn);
        String res = alipayTemplate.pay(payVo);
        return res;
    }
}
